﻿using CommandSystem;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Item;
using MEC;
using RemoteAdmin;
using RgCore.Modules;
using System;
using UnityEngine;

namespace DevTool
{
    public class Cmd : ICommand
    {
        public static CoroutineHandle coroutine;
        public string Command => "d";

        public string[] Aliases => Array.Empty<string>();

        public string Description => "";
        public static GameObject fakePlayer = null;
        public static DateTime Last = DateTime.MinValue;
        public static Vector3 position = Vector3.zero;

        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            response = "OK";
            Player player = Player.Get(sender);
            switch (arguments.At(0))
            {
                case "dummy":
                    Npc.Spawn("Dummy", PlayerRoles.RoleTypeId.ClassD, 111, "test@dummy", player.Position);
                    return true;
                case "rotation":
                    Log.Info($"朝向:{player.Rotation}");
                    return true;
                case "hint":
                    return true;
            }

            return true;
        }
    }

    public class DevTool : RgPlugin
    {
        public override string Name => "开发工具";

        public override string Id => "dev_tool";
        private Cmd command;

        public override void OnDisabled()
        {
            base.OnDisabled();
            CommandProcessor.RemoteAdminCommandHandler.UnregisterCommand(command);
            Exiled.Events.Handlers.Item.ChangingAttachments -= Item_ChangingAttachments;
        }

        public override void OnEnabled()
        {
            base.OnEnabled();
            command = new Cmd();
            CommandProcessor.RemoteAdminCommandHandler.RegisterCommand(command);
            Exiled.Events.Handlers.Item.ChangingAttachments += Item_ChangingAttachments;
        }

        private void Item_ChangingAttachments(ChangingAttachmentsEventArgs ev)
        {
            Log.Info(ev.NewCode);
        }
    }
}